import request from '@/utils/request'

// 模拟数据
const mockActivityList = [
  {
    id: 1,
    title: '双11大促活动',
    description: '一年一度的购物狂欢节,限时秒杀,数量有限!',
    image: '/static/images/activity/activity1.jpg',
    status: 'active',
    startTime: '2024-07-29 00:00:00',
    endTime: '2024-08-01 11:30:00'
  },
  {
    id: 2,
    title: 'iPhone 15 Pro 限时秒杀',
    description: 'iPhone 15 Pro 新品上市,限时特价,抢购从速!',
    image: '/static/images/activity/activity2.jpg',
    status: 'upcoming',
    startTime: '2024-12-01 10:00:00',
    endTime: '2024-12-01 18:00:00'
  },
  {
    id: 3,
    title: '年货节大促销',
    description: '春节年货节,各种商品超低价,先到先得!',
    image: '/static/images/activity/activity3.jpg',
    status: 'upcoming',
    startTime: '2024-12-20 09:00:00',
    endTime: '2024-12-25 23:59:00'
  },
  {
    id: 4,
    title: '数码产品专场',
    description: '数码产品专场秒杀,手机、平板、电脑应有尽有!',
    image: '/static/images/activity/activity4.jpg',
    status: 'ended',
    startTime: '2024-11-25 14:00:00',
    endTime: '2024-11-25 22:00:00'
  }
]

const mockProductList = {
  1: [
    {
      id: 101,
      title: '苹果 iPhone 15 Pro Max',
      image: '/static/images/products/iphone.jpg',
      currentPrice: 8999,
      originalPrice: 9999,
      tags: ['限时特价', '热销'],
      stock: 50,
      soldCount: 30
    },
    {
      id: 102,
      title: '华为 Mate 60 Pro',
      image: '/static/images/products/huawei.jpg',
      currentPrice: 6999,
      originalPrice: 7999,
      tags: ['新品', '推荐'],
      stock: 80,
      soldCount: 45
    },
    {
      id: 103,
      title: '小米 14 Ultra',
      image: '/static/images/products/xiaomi.jpg',
      currentPrice: 5999,
      originalPrice: 6999,
      tags: ['性价比'],
      stock: 100,
      soldCount: 60
    },
    {
      id: 104,
      title: 'OPPO Find X7',
      image: '/static/images/products/oppo.jpg',
      currentPrice: 4999,
      originalPrice: 5999,
      tags: ['拍照神器'],
      stock: 70,
      soldCount: 35
    }
  ],
  2: [
    {
      id: 201,
      title: 'iPhone 15 Pro 256GB',
      image: '/static/images/products/iphone15pro.jpg',
      currentPrice: 7999,
      originalPrice: 8999,
      tags: ['限时秒杀', '新品'],
      stock: 20,
      soldCount: 15
    },
    {
      id: 202,
      title: 'iPhone 15 Pro 512GB',
      image: '/static/images/products/iphone15pro-512.jpg',
      currentPrice: 8999,
      originalPrice: 9999,
      tags: ['限时秒杀', '大容量'],
      stock: 15,
      soldCount: 10
    }
  ],
  3: [
    {
      id: 301,
      title: '年货大礼包A',
      image: '/static/images/products/newyear-gift1.jpg',
      currentPrice: 199,
      originalPrice: 299,
      tags: ['年货节', '超低价'],
      stock: 200,
      soldCount: 150
    },
    {
      id: 302,
      title: '年货大礼包B',
      image: '/static/images/products/newyear-gift2.jpg',
      currentPrice: 299,
      originalPrice: 399,
      tags: ['年货节', '精选'],
      stock: 150,
      soldCount: 100
    },
    {
      id: 303,
      title: '年货大礼包C',
      image: '/static/images/products/newyear-gift3.jpg',
      currentPrice: 399,
      originalPrice: 599,
      tags: ['年货节', '豪华版'],
      stock: 100,
      soldCount: 80
    }
  ],
  4: [
    {
      id: 401,
      title: '华为 Mate 60 Pro',
      image: '/static/images/products/huawei-mate60.jpg',
      currentPrice: 6999,
      originalPrice: 7999,
      tags: ['数码专场', '热销'],
      stock: 30,
      soldCount: 25
    },
    {
      id: 402,
      title: 'iPad Pro 12.9英寸',
      image: '/static/images/products/ipad-pro.jpg',
      currentPrice: 5999,
      originalPrice: 6999,
      tags: ['数码专场', '平板'],
      stock: 25,
      soldCount: 20
    },
    {
      id: 403,
      title: 'MacBook Air M2',
      image: '/static/images/products/macbook-air.jpg',
      currentPrice: 7999,
      originalPrice: 8999,
      tags: ['数码专场', '电脑'],
      stock: 20,
      soldCount: 15
    },
    {
      id: 404,
      title: 'AirPods Pro 2',
      image: '/static/images/products/airpods-pro.jpg',
      currentPrice: 1499,
      originalPrice: 1999,
      tags: ['数码专场', '耳机'],
      stock: 50,
      soldCount: 40
    }
  ]
}

// 活动相关API
export default {
  // 获取活动列表
  getActivityList(params = {}) {
    // 模拟API调用
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: mockActivityList,
          message: '获取成功'
        })
      }, 500)
    })
    
    // 真实API调用
    // return request({
    //   url: '/activity/list',
    //   method: 'GET',
    //   params
    // })
  },

  // 获取活动详情
  getActivityDetail(id) {
    // 模拟API调用
    return new Promise((resolve) => {
      setTimeout(() => {
        const activity = mockActivityList.find(item => item.id == id) || {}
        const detail = {
          ...activity,
          bannerImage: activity.image,
          rules: '1. 活动期间，所有商品享受相应折扣\n2. 每人限购数量以商品详情页为准\n3. 活动商品不支持退换货\n4. 最终解释权归本平台所有',
          totalParticipants: Math.floor(Math.random() * 10000) + 1000,
          totalSales: Math.floor(Math.random() * 1000000) + 100000,
          totalOrders: Math.floor(Math.random() * 5000) + 500
        }
        resolve({
          code: 200,
          data: detail,
          message: '获取成功'
        })
      }, 300)
    })
    
    // 真实API调用
    // return request({
    //   url: `/activity/detail/${id}`,
    //   method: 'GET'
    // })
  },

  // 获取活动关联的商品
  getActivityProducts(params = {}) {
    // 模拟API调用
    return new Promise((resolve) => {
      setTimeout(() => {
        const activityId = params.activityId || 1
        const products = mockProductList[activityId] || []
        resolve({
          code: 200,
          data: products,
          message: '获取成功'
        })
      }, 300)
    })
    
    // 真实API调用
    // return request({
    //   url: '/activity/products',
    //   method: 'GET',
    //   params
    // })
  },

  // 获取活动商品详情
  getActivityProductDetail(params = {}) {
    // 模拟API调用
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: {
            id: params.productId || 101,
            title: '商品详情',
            description: '商品详细描述',
            price: 999,
            images: ['/static/images/products/detail1.jpg']
          },
          message: '获取成功'
        })
      }, 200)
    })
    
    // 真实API调用
    // return request({
    //   url: '/activity/product/detail',
    //   method: 'GET',
    //   params
    // })
  },

  // 参与活动
  joinActivity(data) {
    // 模拟API调用
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: { success: true },
          message: '参与成功'
        })
      }, 500)
    })
    
    // 真实API调用
    // return request({
    //   url: '/activity/join',
    //   method: 'POST',
    //   data
    // })
  },

  // 获取我的活动
  getMyActivities(params = {}) {
    // 模拟API调用
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: mockActivityList.slice(0, 2), // 只返回前两个活动作为我的活动
          message: '获取成功'
        })
      }, 300)
    })
    
    // 真实API调用
    // return request({
    //   url: '/activity/my',
    //   method: 'GET',
    //   params
    // })
  },

  // 活动签到
  activityCheckIn(data) {
    // 模拟API调用
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: { 
            success: true,
            checkInDate: new Date().toISOString(),
            points: 10
          },
          message: '签到成功'
        })
      }, 300)
    })
    
    // 真实API调用
    // return request({
    //   url: '/activity/checkin',
    //   method: 'POST',
    //   data
    // })
  },

  // 获取活动统计数据
  getActivityStats(id) {
    // 模拟API调用
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: {
            totalParticipants: Math.floor(Math.random() * 10000) + 1000,
            totalSales: Math.floor(Math.random() * 1000000) + 100000,
            totalOrders: Math.floor(Math.random() * 5000) + 500
          },
          message: '获取成功'
        })
      }, 200)
    })
    
    // 真实API调用
    // return request({
    //   url: `/activity/stats/${id}`,
    //   method: 'GET'
    // })
  }
} 